package com.tjh.see.controller;

import com.tjh.see.common.WebPageInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 公共控制器
 */
public abstract class WebBaseController {
    /**
     * 设置网页的基本信息
     *
     * @param title
     * @param description
     * @param keywords
     */
    public void setTDK(String title, String description, String keywords){
        //拿到request去添加参数
        ServletRequestAttributes requestAttributes =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (requestAttributes != null) {
            HttpServletRequest request = requestAttributes.getRequest();
            WebPageInfo webPageInfo = new WebPageInfo(
                    title,
                    description,
                    keywords
            );
            request.setAttribute("webPageInfo", webPageInfo);
        }

    }
}
